define(function(require,exports,module) {
    // 曝光可视区域元素
    var visualArea = require('./visualAreaInfo');
    //广告轮播
    var oSilderImg = $('.js_silderImg');        //广告轮播框
    var oPagin = $('.js_pagin');                //个数点
    var indexSwiperAD = [];
    var locationHref = window.location.href;
    var LoopOff = true;
    var ddjAction = '';
    var ddjActionOff = true;
    var ddjActionPositionId  = {};

    // 判断是物品详情时 做处理
    if(locationHref.indexOf('h/goodspay/goodsView') > 1) {
        LoopOff = false;
        ddjActionPositionId.positionId = 2
    }

    /*----2018-4-13-lou添加------*/
    var resizeTimer = null;
    var oWindow = $(window);


    Swiper_indexAD();
    // 页面尺寸修改
    oWindow.on('resize',function() {
        if (resizeTimer) {
            clearTimeout(resizeTimer)
        }
        resizeTimer = setTimeout(function(){
            Swiper_indexAD();
        }, 400);

    });

    function Swiper_indexAD() {
        oSilderImg.each(function (i) {
            // 设置滚动条展示位置 1 为首页
            if( oSilderImg.eq(i).parents('.js_slidePageWrap').length > 0 ) {
                ddjActionPositionId.positionId = 1;
                // ddjActionPositionId.positionType = '首页-推荐';
                ddjActionPositionId.positionFirst = '首页';
                ddjActionPositionId.positionSecond = '推荐';
            }


            if(indexSwiperAD[i] == undefined || indexSwiperAD[i] === '') {
                if(oSilderImg.eq(i).find('.swiper-slide').length < 2){

                }else {
                    indexSwiperAD = oSilderImg.eq(i).swiper({
                        pagination: oPagin.eq(i),
                        loop: LoopOff,
                        autoplay: 3000,
                        autoplayDisableOnInteraction : false,
                        onSlideChangeEnd: function (swiper) {
                            var index = swiper.activeIndex;
                            var _iNow = 0;
                            if(LoopOff) _iNow = 1;
                            if(index > _iNow && ddjActionOff) {
                                ddjAction.viewGoods( oSilderImg.eq(i).find('.swiper-wrapper') );
                            }
                        },
                        onReachEnd: function () {
                            // console.log('最后一个了')
                            ddjActionOff = false;
                        }
                    });
                }
            }
            else {
                indexSwiperAD[i].onResize()
            }

        })
    }



    // 用户行为
    ddjAction = {
        viewGoods: function (obj) {
            // 统计曝光数据
            visualArea.viewEl.showViewEls( obj, function (data, dataJson) {
                ddjhoc.setData(data, 'rec_show', 'add', function () {
                    // console.log('ddjhoc.params.rec_show.swiperAds', ddjhoc.params);
                    if( ddjhoc.params.length != 0 ) ddjhoc.sendData( ddjhoc.params );

                    console.log('ddjhoc.ddjParams.rec_show.swiperAds', ddjhoc.ddjParams);
                    if( ddjhoc.ddjParams.length != 0 ) ddjhoc.sendDDJData( ddjhoc.ddjParams );
                }, dataJson, ddjActionPositionId);
            });
        }
    }
});
